home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / zchar42.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  5.1 KB  |  176 lines

  1. /* Copyright (C) 1996, 1997, 1998, 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: zchar42.c,v 1.2.2.1 2000/10/26 12:45:11 igorm Exp $ */
  20. /* Type 42 character display operator */
  21. #include "ghost.h"
  22. #include "oper.h"
  23. #include "gsmatrix.h"
  24. #include "gspaint.h"        /* for gs_fill, gs_stroke */
  25. #include "gspath.h"
  26. #include "gxfixed.h"
  27. #include "gxfont.h"
  28. #include "gxfont42.h"
  29. #include "gxistate.h"
  30. #include "gxpath.h"
  31. #include "gxtext.h"
  32. #include "gzstate.h"        /* only for ->path */
  33. #include "dstack.h"        /* only for systemdict */
  34. #include "estack.h"
  35. #include "ichar.h"
  36. #include "icharout.h"
  37. #include "ifont.h"        /* for font_param */
  38. #include "igstate.h"
  39. #include "store.h"
  40.  
  41. /* <font> <code|name> <name> <glyph_index> .type42execchar - */
  42. private int type42_fill(P1(i_ctx_t *));
  43. private int type42_stroke(P1(i_ctx_t *));
  44. private int
  45. ztype42execchar(i_ctx_t *i_ctx_p)
  46. {
  47.     os_ptr op = osp;
  48.     gs_font *pfont;
  49.     int code = font_param(op - 3, &pfont);
  50.     gs_font_base *const pbfont = (gs_font_base *) pfont;
  51.     gs_text_enum_t *penum = op_show_find(i_ctx_p);
  52.     int present;
  53.     double sbw[4];
  54.  
  55.     if (code < 0)
  56.     return code;
  57.     if (penum == 0 ||
  58.     (pfont->FontType != ft_TrueType &&
  59.      pfont->FontType != ft_CID_TrueType)
  60.     )
  61.     return_error(e_undefined);
  62.     /*
  63.      * Any reasonable implementation would execute something like
  64.      *  1 setmiterlimit 0 setlinejoin 0 setlinecap
  65.      * here, but apparently the Adobe implementations aren't reasonable.
  66.      *
  67.      * If this is a stroked font, set the stroke width.
  68.      */
  69.     if (pfont->PaintType)
  70.     gs_setlinewidth(igs, pfont->StrokeWidth);
  71.     check_estack(3);        /* for continuations */
  72.     /*
  73.      * Execute the definition of the character.
  74.      */
  75.     if (r_is_proc(op))
  76.     return zchar_exec_char_proc(i_ctx_p);
  77.     /*
  78.      * The definition must be a Type 42 glyph index.
  79.      * Note that we do not require read access: this is deliberate.
  80.      */
  81.     check_type(*op, t_integer);
  82.     check_ostack(3);        /* for lsb values */
  83.     present = zchar_get_metrics(pbfont, op - 1, sbw);
  84.     if (present < 0)
  85.     return present;
  86.     /* Establish a current point. */
  87.     code = gs_moveto(igs, 0.0, 0.0);
  88.     if (code < 0)
  89.     return code;
  90.     /* Get the metrics and set the cache device. */
  91.     if (present == metricsNone) {
  92.     float sbw42[4];
  93.     int i;
  94.  
  95.     code = gs_type42_get_metrics((gs_font_type42 *) pfont,
  96.                      (uint) op->value.intval, sbw42);
  97.     if (code < 0)
  98.         return code;
  99.     for (i = 0; i < 4; ++i)
  100.         sbw[i] = sbw42[i];
  101.     }
  102.     return zchar_set_cache(i_ctx_p, pbfont, op - 1,
  103.                (present == metricsSideBearingAndWidth ?
  104.                 sbw : NULL),
  105.                sbw + 2, &pbfont->FontBBox,
  106.                type42_fill, type42_stroke, NULL);
  107. }
  108.  
  109. /* Continue after a CDevProc callout. */
  110. private int type42_finish(P2(i_ctx_t *i_ctx_p,
  111.                  int (*cont)(P1(gs_state *))));
  112. private int
  113. type42_fill(i_ctx_t *i_ctx_p)
  114. {
  115.     return type42_finish(i_ctx_p, gs_fill);
  116. }
  117. private int
  118. type42_stroke(i_ctx_t *i_ctx_p)
  119. {
  120.     return type42_finish(i_ctx_p, gs_stroke);
  121. }
  122. /* <font> <code|name> <name> <glyph_index> <sbx> <sby> %type42_{fill|stroke} - */
  123. /* <font> <code|name> <name> <glyph_index> %type42_{fill|stroke} - */
  124. private int
  125. type42_finish(i_ctx_t *i_ctx_p, int (*cont) (P1(gs_state *)))
  126. {
  127.     os_ptr op = osp;
  128.     gs_font *pfont;
  129.     int code;
  130.     gs_text_enum_t *penum = op_show_find(i_ctx_p);
  131.     double sbxy[2];
  132.     gs_point sbpt;
  133.     gs_point *psbpt = 0;
  134.     os_ptr opc = op;
  135.  
  136.     if (!r_has_type(op - 3, t_dictionary)) {
  137.     check_op(6);
  138.     code = num_params(op, 2, sbxy);
  139.     if (code < 0)
  140.         return code;
  141.     sbpt.x = sbxy[0];
  142.     sbpt.y = sbxy[1];
  143.     psbpt = &sbpt;
  144.     opc -= 2;
  145.     }
  146.     check_type(*opc, t_integer);
  147.     code = font_param(opc - 3, &pfont);
  148.     if (code < 0)
  149.     return code;
  150.     if (penum == 0 || (pfont->FontType != ft_TrueType &&
  151.                pfont->FontType != ft_CID_TrueType)
  152.     )
  153.     return_error(e_undefined);
  154.     /*
  155.      * We have to disregard penum->pis and penum->path, and render to
  156.      * the current gstate and path.  This is a design bug that we will
  157.      * have to address someday!
  158.      */
  159.     code = gs_type42_append((uint)opc->value.intval, (gs_imager_state *)igs,
  160.                 igs->path, &penum->log2_scale,
  161.                 (penum->text.operation & TEXT_DO_ANY_CHARPATH) != 0,
  162.                 pfont->PaintType, (gs_font_type42 *)pfont);
  163.     if (code < 0)
  164.     return code;
  165.     pop((psbpt == 0 ? 4 : 6));
  166.     return (*cont)(igs);
  167. }
  168.  
  169. /* ------ Initialization procedure ------ */
  170.  
  171. const op_def zchar42_op_defs[] =
  172. {
  173.     {"4.type42execchar", ztype42execchar},
  174.     op_def_end(0)
  175. };
  176.